<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        * {
            margin: 0;
            padding: 0;
        }

        ol li {
            list-style: none;
        }

        body {
            width: 100%;
            height: 3680px;
        }

        div {
            position: relative;
            width: 100%;
            height: 736px;
        }

        .box1 {
            background: red;
        }

        .box2 {
            background: blue;
        }

        .box3 {
            background: lightcyan;
        }

        .box4 {
            background: green;
        }

        .box5 {
            background: pink;
        }

        ol {

            position: fixed;
            top: 50%;
            right: 2rem;
            width: 20px;
            height: 120px;
            border: 1px solid #fff;
        }

        ol li {
            margin-top: 5px;
            width: 16px;
            height: 16px;
            background: #fff;
            border-radius: 50%;
            cursor: pointer;

        }

        ol li.current {
            background: skyblue;
        }
    </style>
</head>

<body>
    <div class="box1">11111</div>
    <div class="box2">22222</div>
    <div class="box3">33333</div>
    <div class="box4">44444</div>
    <div class="box5">55555</div>
    <ol>
        <li class="current"></li>
        <li></li>
        <li></li>
        <li></li>
        <li></li>
    </ol>
    <script src="animate.js"></script>
    <script>
        // 需求：1.点击小圆点切换到对应的屏幕上
        //     2.右边滚动条滚动，对应的小圆点高亮

        // 获取元素

        var box = $("div");

        var circle = $("li");
        var scroll = document.documentElement.scrollTop || document.body.scrollTop;

        for (var i = 0; i < circle.length; i++) {
            circle[i].setAttribute('index', i);

            circle[i].onclick = function () {
                // 排他
                paita();
                var liIndex = this.getAttribute("index");
                document.documentElement.scrollTop = (liIndex) * 736;
                // 使用动画时有延时问题，鸡肋
                // animate(document,liIndex*736);

                // console.log(liIndex);
            }
        }

        window.onscroll = function () {
            var scroll = document.documentElement.scrollTop || document.body.scrollTop;

            if(scroll<736){
                paita();
                circle[0].className = "current";
            } else if(scroll<736*2){
                paita();
                circle[1].className = "current";
            } else if(scroll<736*3){
                paita();
                circle[2].className = "current";
            }else if(scroll<736*4){
                paita();
                circle[3].className = "current";
            }else {
                paita();
                circle[4].className = "current";
            } 
            // for (let num = 1; i < 5; i++) {
            //     if (scroll < num * 736) {
            //         for (var j = 0; j < circle.length; j++) {
            //             circle[j].className = "";
            //         }
            //         circle[i-1].className = "current";
            //     }else {
            //         for (var j = 0; j < circle.length; j++) {
            //             circle[j].className = "";
            //         }
            //         circle[4].className = "current";
            //     }
            // }
            // document.documentElement.scrollTop = 736*4;
            // console.log(scroll);
            // num++;
        }


         function paita(){
            for(var j=0;j<circle.length;j++){
                    circle[j].className = "";
                }
         }
        
        function $(select) {
            return document.querySelectorAll(select);
        }
    </script>
</body>

</html>